package com.hotel.utils;

import sun.misc.BASE64Decoder;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;

public class Base64ToImgUtil {

    /**
     * 对Base64进行解码操作同时转换成png文件(路径整合之后修改为相对路径)
     * @param Base64Str
     * @return
     * @throws IOException
     */
    public static FileInputStream Base64ToImg(String Base64Str) throws IOException {
        BASE64Decoder decoder = new BASE64Decoder();
        //刚刚将字节数组转成的字符串
        byte[] imgbyte = decoder.decodeBuffer(Base64Str.split(",")[1]);
        String imageName = UUID.randomUUID().toString();
        OutputStream os = new FileOutputStream("D:\\ChiXingEdu\\BigPro\\imitation-tuniu-website\\qiniuImages\\"+imageName+".png");
        os.write(imgbyte);
        os.flush();
        os.close();
        FileInputStream imagePng = new FileInputStream("D:\\ChiXingEdu\\BigPro\\imitation-tuniu-website\\qiniuImages\\"+imageName+".png");
        return imagePng;
    }


}
